package com.think.teaching.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.think.teaching.model.Class;

import java.util.List;

import org.apache.ibatis.annotations.*;
import org.apache.ibatis.mapping.FetchType;

/**
 * <p>
 * 班级 Mapper 接口
 * </p>
 *
 * @author think
 * @since 2020-08-12
 */
public interface ClassMapper extends BaseMapper<Class> {
	
	
	@Select("<script>" +
			"SELECT * FROM class WHERE delflag =0 " +
			"<if test='state gt 0'> AND state =#{state}</if>" +
			"AND class.major IN (SELECT major.id FROM major,college,school WHERE major.college=college.id AND school.id=college.school"+ 
			"<if test='major gt 0'> AND major.id =#{major}</if>" +
			"<if test='college gt 0'> AND college.id =#{college}</if>" +
			"<if test='school gt 0'> AND school.id =#{school}</if>)" +
			"</script>"
	)
	@Results({
		@Result(column="id",property="id"),
		@Result(column="class_index",property="classIndex"),
		@Result(column="grade",property="grade"),
		@Result(column="state",property="state"),
		@Result(column="updated_time",property="updatedTime"),
		@Result(column="teacher",property="teacherInfo",
		one=@One(select="com.think.teaching.mapper.TeacherInfoMapper.getInfoById",fetchType= FetchType.EAGER)),
		@Result(column="major",property="majorInfo",
		one=@One(select="com.think.teaching.mapper.MajorMapper.getInfoById",fetchType= FetchType.EAGER))
	})
	IPage<Class> getClassList(IPage<Class> page,
							  @Param("major") Integer major,
							  @Param("college") Integer college,
							  @Param("school") Integer school,
							  @Param("state") Integer state);
	
	@Select(value = "SELECT * FROM class WHERE id=#{id} Limit 1")
	@Result(column="id",property="id")
	@Result(column="class_index",property="classIndex")
	@Result(column="grade",property="grade")
	@Result(column="state",property="state")
	@Result(column="updated_time",property="updatedTime")
	@Result(column="teacher",property="teacherInfo",
	one=@One(select="com.think.teaching.mapper.TeacherInfoMapper.getInfoById",fetchType= FetchType.EAGER))
	@Result(column="major",property="majorInfo",
	one=@One(select="com.think.teaching.mapper.MajorMapper.getInfoById",fetchType= FetchType.EAGER))
	Class getClassDetailes(Integer id);
	
}
